package com.ruoyi.system.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.Area;
import com.ruoyi.system.domain.BusinessLine;
import com.ruoyi.system.domain.SysPost;
import com.ruoyi.system.mapper.AreaMapper;
import com.ruoyi.system.service.IAreaService;
import com.ruoyi.system.service.IBusinessLineService;
import com.ruoyi.system.service.ISysPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.CustomerMapper;
import com.ruoyi.system.domain.Customer;
import com.ruoyi.system.service.ICustomerService;

/**
 * 客户信息Service业务层处理
 *
 * @author ruoyi
 * @date 2023-07-18
 */
@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements ICustomerService {
    @Autowired
    private CustomerMapper customerMapper;
    @Autowired
    private IAreaService areaService;

    @Autowired
    private ISysPostService sysPostService;
    @Autowired
    private IBusinessLineService businessLineService;




    /**
     * 查询客户信息
     *
     * @param id 客户信息主键
     * @return 客户信息
     */
    @Override
    public Customer selectCustomerById(Long id) {
        return customerMapper.selectCustomerById(id);
    }

    /**
     * 查询客户信息列表
     *
     * @param customer 客户信息
     * @return 客户信息
     */
    @Override
    public List<Customer> selectCustomerList(Customer customer) {
        return customerMapper.selectCustomerList(customer);
    }

    /**
     * 新增客户信息
     *
     * @param customer 客户信息
     * @return 结果
     */
    @Override
    public int insertCustomer(Customer customer) {
        return customerMapper.insertCustomer(customer);
    }

    /**
     * 修改客户信息
     *
     * @param customer 客户信息
     * @return 结果
     */
    @Override
    public int updateCustomer(Customer customer) {
        return customerMapper.updateCustomer(customer);
    }

    /**
     * 批量删除客户信息
     *
     * @param ids 需要删除的客户信息主键
     * @return 结果
     */
    @Override
    public int deleteCustomerByIds(Long[] ids) {
        return customerMapper.deleteCustomerByIds(ids);
    }

    /**
     * 删除客户信息信息
     *
     * @param id 客户信息主键
     * @return 结果
     */
    @Override
    public int deleteCustomerById(Long id) {
        return customerMapper.deleteCustomerById(id);
    }

    @Override
    public int add(Customer customer) {
        Area area = areaService.getById(customer.getAreaId());
        SysPost sysPost = sysPostService.selectPostById(customer.getPostId());
        BusinessLine businessLine = businessLineService.getById(customer.getBusinessLineId());
        customer.setAreaName(area.getName());
        customer.setPostName(sysPost.getPostName());
        customer.setBusinessLineName(businessLine.getName());
        boolean save = save(customer);
        if (save) return 1;

        return 0;
    }
}
